// SBp_BPA.cpp: implementation of the CSBp_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/SBp_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSBp_BPA::CSBp_BPA()
{
	m_chType = 'S';
	m_chSubType = 'B';
	m_chChangeCode = '+';

	m_dT8 = 0;
	m_dT9 = 0;
	m_chM = '0';
	m_chN = '0';
	m_dKs1 = 0;
	m_dT1 = 0;
	m_dT2 = 0;
	m_dT3 = 0;
	m_dT4 = 0;
	m_dVpmax = 0;
	m_dVpmin = 0;

	m_strCardType[0] = 'S';
}

CSBp_BPA::CSBp_BPA(CSBp_BPA &sbpBPA):CUnit_BPA(sbpBPA)
{
	m_dT8 = sbpBPA.m_dT8;
	m_dT9 = sbpBPA.m_dT9;
	m_chM = sbpBPA.m_chM;
	m_chN = sbpBPA.m_chN;
	m_dKs1 = sbpBPA.m_dKs1;
	m_dT1 = sbpBPA.m_dT1;
	m_dT2 = sbpBPA.m_dT2;
	m_dT3 = sbpBPA.m_dT3;
	m_dT4 = sbpBPA.m_dT4;
	m_dVpmax = sbpBPA.m_dVpmax;
	m_dVpmin = sbpBPA.m_dVpmin;
}

CSBp_BPA::~CSBp_BPA()
{

}

bool CSBp_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CSBp_BPA::FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
		return true;	

	m_dT8 = StrToDouble(&buffer[16],5,0);
	if(EndOfSec(&buffer[16],5))
		return true;

	m_dT9 = StrToDouble(&buffer[21],5,0);
	if(EndOfSec(&buffer[21],5))
		return true;

	m_chM = buffer[26];
	if(EndOfSec(&buffer[26],1))
		return true;

	m_chN = buffer[27];
	if(EndOfSec(&buffer[27],1))
		return true;

	m_dKs1 = StrToDouble(&buffer[28],5,0);
	if(EndOfSec(&buffer[28],5))
		return true;

	m_dT1 = StrToDouble(&buffer[33],5,0);
	if(EndOfSec(&buffer[33],5))
		return true;

	m_dT2 = StrToDouble(&buffer[38],5,0);
	if(EndOfSec(&buffer[38],5))
		return true;

	m_dT3 = StrToDouble(&buffer[43],5,0);
	if(EndOfSec(&buffer[43],5))
		return true;

	m_dT4 = StrToDouble(&buffer[48],5,0);
	if(EndOfSec(&buffer[48],5))
		return true;

	m_dVpmax = StrToDouble(&buffer[53],5,0);
	if(EndOfSec(&buffer[53],5))
		return true;

	m_dVpmin = StrToDouble(&buffer[58],5,0);
	if(EndOfSec(&buffer[58],5))
		return true;

	return true;
}

bool CSBp_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CSBp_BPA::UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dT8,&buffer[16],5,0);
	DoubleToStr(m_dT9,&buffer[21],5,0);
	buffer[26] = m_chM;
	buffer[27] = m_chN;
	DoubleToStr(m_dKs1,&buffer[28],5,0);
	DoubleToStr(m_dT1,&buffer[33],5,0);
	DoubleToStr(m_dT2,&buffer[38],5,0);
	DoubleToStr(m_dT3,&buffer[43],5,0);
	DoubleToStr(m_dT4,&buffer[48],5,0);
	DoubleToStr(m_dVpmax,&buffer[53],5,0);
	DoubleToStr(m_dVpmin,&buffer[58],5,0);

	return true;
}